﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AUV5.Web.Pages
{
    public partial class Share : PageBaseFrontend
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (IsVerified)
                {
                    hfAuth.Value = Session.SessionID;
                    hfAspSessID.Value = Session.SessionID;
                    hfadddate.Value = DateTime.Now.ToString("yyyy-MM-dd");

                    if (Request["serviceID"] != null)
                    {
                        Model.ServiceInfo service = BLL.ServiceInfoBLL.Instance.GetDetail(Request["serviceID"]);
                        if (service != null)
                        {
                            lbServiceTitle.Text = service.Title;
                            lbServiceCategory.Text = service.CategoryName;
                        }
                        else
                        {
                            base.NoticeInfo = "无效的服务";
                            Response.Redirect("/Pages/ServiceManage.aspx");
                        }
                    }
                    else
                    {
                        base.NoticeInfo = "参数错误！";
                        Response.Redirect("/Pages/ServiceManage.aspx");
                    }
                }
                else
                {
                    Response.Redirect(URL_LOGIN);
                }
            }
        }

        protected void btnShare_Click(object sender, EventArgs e)
        {
            if (Request["serviceID"] != null)
            {
                string serviceID = Request["serviceID"];

                string description = txtDescription.Text.Trim();

                Common.Enum.AttachFormat format = Common.Enum.AttachFormat.None;
                string attachpath = "";

                if (hfpath.Value == "" && hfvideopath.Value == "")
                {
                    lbMessage.Text = "请上传要分享的成果";
                    return;
                }

                else if (hfvideopath.Value != "")
                {
                    format = Common.Enum.AttachFormat.Video;
                    attachpath = hfvideopath.Value;
                }

                else if (hfpath.Value != "")
                {
                    format = Common.Enum.AttachFormat.Image;
                    attachpath = hfpath.Value;
                }

                BLL.WorksShareBLL.Instance.AddWorkShare(VerifiedUserID, serviceID, description, format, attachpath);
                Response.Redirect(URL_INDEX);
            }
        }
    }
}